<?php
/*
 * [JINYUN!] (C)2001-2099 Jinyunweb.com
 * This is NOT a freeware, use is subject to license terms
 * $Id: 2017-12-13 03:39:35 apple $
*/
/*
	页面模版分类管理
*/
defined('BY_JYA') or exit('error');
$_RQ['op']=$_RQ['op']?$_RQ['op']:'list';
$return=array();
if($_RQ['op']=='list'){
	$params=array();
	if(!empty($_RQ['title'])){
		$params['title like']='%'.trim($_RQ['title']).'%';
		$return['params']['title']=$_RQ['title'];
	}
	$orderby='id desc';
	$pindex = max(1, intval($_RQ['page']));
	$psize = 10;
	$total='';
	$fields=array('id','title');
	$list=pdo_getslice('core_template_group',$params,array($pindex,$psize),$total,$fields,'id',$orderby);
	$return['list']=$list?$list:array();
	$totalpage=ceil($total/$psize);
	$totalpage=intval($totalpage);
	$return['totalpage'] =$totalpage;
	$return['params']['page'] =$pindex;
	$htmls=array(
		'type'=>'list',
		'tabs'=>array(
			array('op'=>'list','title'=>'分类列表'),
			array('op'=>'edit','title'=>'添加分类'),
		),
		'list'=>array('data'=>'list','tip'=>'自定义属于自己站点的模板分类！不同于云市场分类','list'=>array(
			array('name'=>'title','title'=>'分类名称','type'=>'string'),
		)),
		'search_one'=>array('name'=>'title'),
	);
	$return['htmls']=$htmls;
	exi($return);
}
if($_RQ['op']=='edit'){
	//编辑微站，添加微站在微站模版列表那边选择模版然后添加
	$id=intval($_RQ['id']);
	if($id){
		$item=pdo_get('core_template_group',array('id'=>$id));
	}else{
		$item=array();
	}
	$return['item']=$item;
	$htmls=array(
		'type'=>'edit',
		'post'=>'post',
		'desc'=>'设置类目信息',
		'tabs'=>array(
			array('op'=>'list','title'=>'分类列表'),
		),
		'edit'=>array(
			array('type'=>'string','name'=>'title','title'=>'分类名称'),
		),
	);
	$return['htmls']=$htmls;
	exi($return);
}
if($_RQ['op']=='post'){
	$post=get_postdata();
	$id=intval($post['id']);
	$data=array(
		'title'=>$post['title'],
	);
	if($id){
		pdo_update('core_template_group',$data,array('id'=>$id));
		exi('添加成功！');
	}else{
		pdo_insert('core_template_group',$data);
		exi('修改成功！');
	}
}
if($_RQ['op']=='del'){
	$id=intval($_RQ['id']);
	if($id){
		pdo_delete('core_template_group',array('id'=>$id));
	}
	$del=trim($_RQ['del'],';');
	if($del){
		$del=explode(';',$del);
		foreach($del as $id){
			$id=intval($id);
			if($id){
				pdo_delete('core_template_group',array('id'=>$id));
			}
		}
	}
	exi('删除成功！');
}